package com.ruoyi.project.platform.controller;

import java.util.List;

import com.ruoyi.project.platform.dto.UserOrderDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.platform.domain.PltUserOrder;
import com.ruoyi.project.platform.service.IPltUserOrderService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 订单Controller
 * 
 * @author ruoyi
 * @date 2020-07-27
 */
@RestController
@RequestMapping("/platform/order")
public class PltUserOrderController extends BaseController
{
    @Autowired
    private IPltUserOrderService pltUserOrderService;

    /**
     * 查询订单列表
     */
    @PreAuthorize("@ss.hasPermi('platform:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(PltUserOrder pltUserOrder)
    {
        startPage();
        List<PltUserOrder> list = pltUserOrderService.selectPltUserOrderList(pltUserOrder);
        return getDataTable(list);
    }

    /**
     * 导出订单列表
     */
    @PreAuthorize("@ss.hasPermi('platform:order:export')")
    @Log(title = "订单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PltUserOrder pltUserOrder)
    {
        List<PltUserOrder> list = pltUserOrderService.selectPltUserOrderList(pltUserOrder);
        ExcelUtil<PltUserOrder> util = new ExcelUtil<PltUserOrder>(PltUserOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:order:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return AjaxResult.success(pltUserOrderService.selectPltUserOrderById(orderId));
    }

    /**
     * 新增订单
     */
    @PreAuthorize("@ss.hasPermi('platform:order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PltUserOrder pltUserOrder)
    {
        return toAjax(pltUserOrderService.insertPltUserOrder(pltUserOrder));
    }

    @PreAuthorize("@ss.hasPermi('platform:order:add')")
    @Log(title = "订单", businessType = BusinessType.INSERT)
    @PostMapping("detail")
    public AjaxResult addOrderInfo(@RequestBody UserOrderDto.OrderInfo orderInfo)
    {
        return toAjax(pltUserOrderService.insertPltUserOrder(orderInfo));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('platform:order:edit')")
    @Log(title = "订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PltUserOrder pltUserOrder)
    {
        return toAjax(pltUserOrderService.updatePltUserOrder(pltUserOrder));
    }

    /**
     * 修改订单
     */
    @PreAuthorize("@ss.hasPermi('platform:order:edit')")
    @Log(title = "支付", businessType = BusinessType.UPDATE)
    @PutMapping("/pay/{orderId}")
    public AjaxResult pay(@PathVariable Long orderId)
    {
        return toAjax(pltUserOrderService.payForOrder(orderId));
    }

    /**
     * 删除订单
     */
    @PreAuthorize("@ss.hasPermi('platform:order:remove')")
    @Log(title = "订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(pltUserOrderService.deletePltUserOrderByIds(orderIds));
    }
}
